#include <bits/stdc++.h>
using namespace std;
int yu[1005], shu[1005], yin[1005], sum[1005];
int n, cnt = 0;
int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> yu[i] >> shu[i] >> yin[i];
        sum[i] = yu[i] + shu[i] + yin[i];
    }
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            if (abs(yu[i] - yu[j]) <= 5 &&
                abs(shu[i] - shu[j]) <= 5 &&
                abs(yin[i] - yin[j]) <= 5 &&
                abs(sum[i] - sum[j]) <= 10){
                    cnt++;
                }
        }
    }
    cout << cnt << endl;
    return 0;
}